# Contributor: Sergei Lukin <sergej.lukin@gmail.com>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
_php=php8
pkgname=postfixadmin
pkgver=3.3.10
pkgrel=0
pkgdesc="Web Based Management tool for Postfix"
url="http://postfixadmin.sourceforge.net/"
arch="noarch"
license="GPL-2.0-or-later"
depends="$_php"
options="!check"
subpackages="$pkgname-doc $pkgname-contrib"
source="https://github.com/postfixadmin/postfixadmin/archive/postfixadmin-$pkgver.tar.gz"

# secfixes:
#   3.0.2-r0:
#     - CVE-2017-5930

builddir="$srcdir/$pkgname-$pkgname-$pkgver"

package() {
	mkdir -p "$pkgdir"/usr/share/webapps/postfixadmin \
		"$pkgdir"/etc/postfixadmin
	cp -r * "$pkgdir"/usr/share/webapps/postfixadmin/

	# move config to /etc/postfixadmin and create symlink
	mv "$pkgdir"/usr/share/webapps/postfixadmin/config.inc.php \
		"$pkgdir"/etc/postfixadmin/
	ln -s /etc/postfixadmin/config.inc.php \
		"$pkgdir"/usr/share/webapps/postfixadmin/config.inc.php
	ln -s /etc/postfixadmin/config.local.php \
		"$pkgdir"/usr/share/webapps/postfixadmin/config.local.php
	mkdir -p "$pkgdir"/var/cache/postfixadmin/templates_c
	ln -s /var/cache/postfixadmin/templates_c \
		"$pkgdir"/usr/share/webapps/postfixadmin/templates_c
	echo -e "User-Agent: *\nDisallow: /" \
		> "$pkgdir"/usr/share/webapps/postfixadmin/robots.txt
}

doc() {
	install -d "$subpkgdir"/usr/share/doc/$pkgname
	mv "$builddir"/*.TXT "$subpkgdir"/usr/share/doc/$pkgname
	mv "$builddir"/DOCUMENTS "$subpkgdir"/usr/share/doc/$pkgname
}

contrib() {
	install -d "$subpkgdir"/usr/share/webapps/$pkgname
	for dir in debian ADDITIONS VIRTUAL_VACATION; do
		mv "$builddir"/$dir "$subpkgdir"/usr/share/webapps/$pkgname/
	done
}

sha512sums="
e00fc9ea343a928976d191adfa01020ee0c6ddbe80a39e01ca2ee414a18247958f033970f378fe4a9974636172a5e094e57117ee9ac7b930c592f433097a7aca  postfixadmin-3.3.10.tar.gz
"
